package com.ideaaedi.springcloud.jd.commonds.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.ideaaedi.springcloud.jd.commonds.enums.user.CertTypeEnum;
import com.ideaaedi.springcloud.jd.commonds.enums.user.UserTypeEnum;

/**
 * easyexecl转换器
 *
 * @author <font size = "20" color = "#3CAA3C"><a href="https://gitee.com/JustryDeng">JustryDeng</a></font> <img src="https://gitee.com/JustryDeng/shared-files/raw/master/JustryDeng/avatar.jpg" />
 * @since 2021.0.1.E
 */
public interface EasyExcelConverter {
    
    /**
     * UserTypeEnum 转换器
     */
    class UserTypeEnumConverter implements Converter<UserTypeEnum> {
        
        @Override
        public Class<?> supportJavaTypeKey() {
            return UserTypeEnum.class;
        }
        
        @Override
        public WriteCellData<UserTypeEnum> convertToExcelData(UserTypeEnum value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
            return new WriteCellData<>(value == null ? "" : value.name());
        }
    }
    
    /**
     * CertTypeEnum 转换器
     */
    class CertTypeEnumConverter implements Converter<CertTypeEnum> {
        
        @Override
        public Class<?> supportJavaTypeKey() {
            return UserTypeEnum.class;
        }
        
        @Override
        public WriteCellData<CertTypeEnum> convertToExcelData(CertTypeEnum value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
            return new WriteCellData<>(value == null ? "" : value.name());
        }
    }
}
